<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>平方练习</title>
</head>
<body>
<input type="text" id="i1">
<input type="button" value="相加" onclick="f()">
<div></div>
<script>
    function f(){
        let i = document.querySelector("#i1");
        let d = document.querySelector("div");
        //判断用户输入的内容是否是NaN
        if (isNaN(i.value)){
            d.innerText="输入信息有误！！！！";
            return;
        }
        //当对字符串进行 - * / 运算时自动转成数值
        // d.innerText = i.value*i.value;
        //进行加法运算 需要手动将字符串转成数值 否则是字符串拼接
        // d.innerText = parseFloat(i.value)+parseFloat(i.value);
        d.innerText = i.value*1+i.value*1;
    }
</script>
</body>
</html>